package com.bootdo.program.wallpaper.controller;

import java.util.List;
import java.util.Map;

import com.bootdo.common.utils.StringUtils;
import com.bootdo.program.wallpaper.domain.AppConnectDO;
import com.bootdo.program.wallpaper.domain.BzTalentDO;
import com.bootdo.program.wallpaper.domain.DistributionProfitDO;
import com.bootdo.program.wallpaper.service.AppConnectService;
import com.bootdo.program.wallpaper.service.BzTalentService;
import com.bootdo.program.wallpaper.service.DistributionProfitService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.bootdo.common.utils.PageUtils;
import com.bootdo.common.utils.Query;
import com.bootdo.common.utils.R;

/**
 * 分销收益表
 * 
 * @author guoyunfei
 * @email 2549789059@qq.com
 * @date 2021-12-10 21:35:19
 */
 
@Controller
@RequestMapping("/wallpaper/distributionProfit")
public class DistributionProfitController {
	@Autowired
	private DistributionProfitService distributionProfitService;

	@Autowired
	private AppConnectService appConnectService;

	@Autowired
	private BzTalentService bzTalentService;
	
	@GetMapping()
	@RequiresPermissions("wallpaper:distributionProfit:distributionProfit")
	String DistributionProfit(){
	    return "wallpaper/distributionProfit/distributionProfit";
	}
	
	@ResponseBody
	@GetMapping("/list")
	@RequiresPermissions("wallpaper:distributionProfit:distributionProfit")
	public PageUtils list(@RequestParam Map<String, Object> params){
		//查询列表数据
        Query query = new Query(params);
		List<DistributionProfitDO> distributionProfitList = distributionProfitService.list(query);
//		distributionProfitList.forEach((tt -> {
//
//			if(StringUtils.isNotBlank(tt.getUserId())){
//				BzTalentDO talentDO = bzTalentService.getByUserId(tt.getUserId());
//				tt.setUserName(null != talentDO ? talentDO.getNickname() : null);
//			}
//
//			if(StringUtils.isNotBlank(tt.getSouUserId())){
//				AppConnectDO connectDO = appConnectService.getByUserId(tt.getSouUserId());
//				if(null != connectDO){
//					tt.setSouUserName(connectDO.getNickName());
//				}
//			}
//		}));
		int total = distributionProfitService.count(query);
		PageUtils pageUtils = new PageUtils(distributionProfitList, total);
		return pageUtils;
	}
	
	@GetMapping("/add")
	@RequiresPermissions("wallpaper:distributionProfit:add")
	String add(){
	    return "wallpaper/distributionProfit/add";
	}

	@GetMapping("/edit/{id}")
	@RequiresPermissions("wallpaper:distributionProfit:edit")
	String edit(@PathVariable("id") Long id,Model model){
		DistributionProfitDO distributionProfit = distributionProfitService.get(id);
		model.addAttribute("distributionProfit", distributionProfit);
	    return "wallpaper/distributionProfit/edit";
	}
	
	/**
	 * 保存
	 */
	@ResponseBody
	@PostMapping("/save")
	@RequiresPermissions("wallpaper:distributionProfit:add")
	public R save( DistributionProfitDO distributionProfit){
		if(distributionProfitService.save(distributionProfit)>0){
			return R.ok();
		}
		return R.error();
	}
	/**
	 * 修改
	 */
	@ResponseBody
	@RequestMapping("/update")
	@RequiresPermissions("wallpaper:distributionProfit:edit")
	public R update( DistributionProfitDO distributionProfit){
		distributionProfitService.update(distributionProfit);
		return R.ok();
	}
	
	/**
	 * 删除
	 */
	@PostMapping( "/remove")
	@ResponseBody
	@RequiresPermissions("wallpaper:distributionProfit:remove")
	public R remove( Long id){
		if(distributionProfitService.remove(id)>0){
		return R.ok();
		}
		return R.error();
	}
	
	/**
	 * 删除
	 */
	@PostMapping( "/batchRemove")
	@ResponseBody
	@RequiresPermissions("wallpaper:distributionProfit:batchRemove")
	public R remove(@RequestParam("ids[]") Long[] ids){
		distributionProfitService.batchRemove(ids);
		return R.ok();
	}
	
}
